<html>
    <head>
        <title>identify.html</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <link href="../../css/general1.css" rel="stylesheet" type="text/css" />
        <link href="style/css.css" rel="stylesheet" type="text/css" />
		<link href="../../zephyr/css/drift.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="../../zephyr/js/Util.js">
		</script>
        <script type="text/javascript" src="../../script/hiawardbpm.js">
        </script>
        <script type="text/javascript" src="../../script/prototype.js">
        </script>
        <script type="text/javascript" src="/vchzms-hiaward/dwr/engine.js">
        </script>
        <script type="text/javascript" src="/vchzms-hiaward/dwr/util.js">
        </script>
        <script type="text/javascript" src="/vchzms-hiaward/dwr/interface/OutService.js">
        </script>
        <script type="text/javascript" src="/vchzms-hiaward/dwr/interface/Dao.js">
        </script>
        <script type="text/javascript" src="/vchzms-hiaward/dwr/interface/Ocx.js">
        </script>
        <script type="text/javascript">
            function subForm(msg){
                var webData = buildWebData(msg);
                var xmlMsg = window.dialogArguments;
                alert(xmlMsg.getXmlDocument().xml);
                xmlMsg.setCommand(12);
                xmlMsg.setWebData(webData);
                xmlMsg.buildXML();
                var url = "/vchzms-hiaward/ProcessAjaxHandler";
                alert(xmlMsg.getXmlDocument().xml);
                new Ajax.Request(url, {
                    method: 'post',
                    postBody: xmlMsg.getXmlDocument().xml,
                    contentType: 'application/x-www-form-urlencoded',
                    encoding: 'UTF-8',
                    onComplete: function(transport){
                        try {
                            if (200 == transport.status) {
                                alert('成功创建了一个新任务');
                                window.close();
                            }
                            if (400 == transport.status) {
                                alert('创建失败');
                            }
                        } 
                        catch (err) {
                            alert('js异常');
                        }
                    }
                });
            }
            
            function buildWebData(msg){
                var webData = new WebData();
                var xmlMsg = window.dialogArguments;
                var vchsid = xmlMsg.getWebData().getProperty('vchsid');
                var amount=$('amount').value;
                alert(msg);
                webData.setProperty('idresult', msg);
                if (msg == '4') {
                    webData.setProperty('idstate', '2');
                }
                else {
                    webData.setProperty('idstate', '3');
                }
                webData.setProperty('vchsidInput', vchsid);
                webData.setProperty('amount', amount);
                return webData;
            }
            
            //查询客户信息和票据信息的函数
            function getVoucherInfo(){
                var xmlMsg = window.dialogArguments;
                var vchsid = xmlMsg.getWebData().getProperty('vchsid');
                Dao.getVoucherById(vchsid, function(rr){
                    var vd = rr.vchdate;
                    $("accno").innerHTML = rr.accno;
                    $("vchno").innerHTML = rr.vchno;
                    $("amount").value = rr.amount;
                    $("vchtype").innerHTML = rr.vchtype;
                    $("vchdate").value = rr.vchdate;
                    $("brbank").innerHTML = rr.brbank;
                    if (rr.batno != null) {
                        $("batno").innerHTML = rr.batno;
                    }
                    OutService.Z_BAPI_ACCOUNT_INFO(rr.accno, function(data){
                        var custid = data.custId;
                        $('coName').innerHTML = data.accName;
                        OutService.Z_BAPI_BP_GET_ORG_DETAIL(custid, function(data){
                            $('connector').innerHTML = data.connector;
                            $('tel').innerHTML = data.tel;
                        });
                    });
                });
                
            }
            
            var flag = true;
            function showImage(){
                flag = !flag;
                if (!flag) {
                    $('image').style.visibility = 'visible';
                    $('img').style.visibility = 'hidden';
                }
                else {
                    $('image').style.visibility = 'hidden';
                    $('img').style.visibility = 'visible';
                }
                
            }
            
            //调用页面验印控件的函数
            function invokeOCX(commandid, xml){
                var xmldata = xml;
                var commandid = commandid;
                var DOcxtest1 = $("idOcx");
                var varRet = null;
                if (xmldata) {
                    varRet = DOcxtest1.Zms(commandid, xmldata);
                }
                //alert("调用控件返回xml信息: " + varRet); //调用控件返回xml信息
            }
            
            //请求验印XML
            function getTradeXML(){
                var xmlMsg = window.dialogArguments;
                var vchsid = xmlMsg.getWebData().getProperty('vchsid');
                Ocx.getIdTradeXML(vchsid,0,'', 0, function(xml){
                    verifyIdTradeXML(xml);
                });
            }
            
            //验证报文，判断是否初始化控件
            function verifyIdTradeXML(idxml){
                //if ($('resub').style.display == '') 
                //    $('resub').style.display == 'none';
                var no = idxml.substring(0, 3);
                if (no != '') {
                    if (no == '<?x') {
                        var xmlDoc = new ActiveXObject("microsoft.xmldom");
                        xmlDoc.async = false;
                        xmlDoc.loadXML(idxml);
                        var combflag = xmlDoc.selectSingleNode("//seal/@combflag").text;
                        if (combflag != "0") {
							$('identifyMessegeBox').value = '有印件组合，金额设置为可输入';
                            $('amount').readOnly = false;
                        }
                        invokeOCX(1014, idxml);
                    }
                    else 
                        if (no != '000') {
                            if (no == 'A02') {
                                $('identifyMessegeBox').value ='查询数据不存在!';
                            }
                            else 
                                if (no == 'A15') {
                                    $('identifyMessegeBox').value = '印鉴处于变更期,出票日期设置为可输入';
                                    $('vchdate').readOnly = false;
                                    //$('resub').style.display = '';
									resub(0);
                                }
                                else {
                                    var msg = idxml.substring(3, idxml.length);
									$('identifyMessegeBox').value = msg;
                                }
                        }
                        else {
                            var xmlDoc = new ActiveXObject("microsoft.xmldom");
                            xmlDoc.async = false;
                            xmlDoc.loadXML(idxml);
                            var combflag = xmlDoc.selectSingleNode("//seal/@combflag").text;
                            if (combflag != "0") {
								$('identifyMessegeBox').value = '有印件组合，金额设置为可输入';
                                $('amount').readOnly = false;
                            }
                            invokeOCX(1014, idxml);
                        }
                }
                else {
                    $('identifyMessegeBox').value ='返回验印报文错误!';
                }
            }
            
            //保存验印结果
            function saveIdResult(){
                var DOcxtest1 = document.getElementById("idOcx");
                var varRet = DOcxtest1.Zms(1006, "");
                alert("保存验印结果返回xml信息: " + varRet); //调用控件返回xml信息
                var xmlMsg = window.dialogArguments;
                var vchsid = xmlMsg.getWebData().getProperty('vchsid');
                Ocx.saveIdResult(1006, varRet, vchsid, function(res){
                    //alert(res);
                });
            }
            
            //重新初始化控件
            function resub(flag){
                var vchdate = $('vchdate').value;
                if (vchdate == '') {
                    alert("凭证日期为空，请重新输入");
                    return;
                }
                else {
                    var xmlMsg = window.dialogArguments;
                    var vchsid = xmlMsg.getWebData().getProperty('vchsid');
					if(flag == 0) {//使用业务数据的凭证日期
						vchdate = '1';
					}
                    Ocx.getIdTradeXML(vchsid, vchdate,'', 0, function(xml){
                        verifyIdTradeXML(xml);
                    });
                }
            }
			
			function amountEnter(event) {
				var amount = $('amount');
				var vchdate = $('vchdate').value;
				if(event.keyCode==13 && !amount.readOnly){//回车事件
					var xmlMsg = window.dialogArguments;
                    var vchsid = xmlMsg.getWebData().getProperty('vchsid');
                    Ocx.getIdTradeXML(vchsid, vchdate,amount.value, 0, function(xml){
                        verifyIdTradeXML(xml);
                    });
				}
			}
			function vchdateEnter(event) {
				if(event.keyCode==13 && !$('vchdate').readOnly){
					resub(1);
				}
			}
        </script>
    </head>
    <body onLoad="initMask();getVoucherInfo();getTradeXML()">
    	<div id="fade" class="black_overlay"></div>
        <div id="image" style="left: 10px;top: 10px;position: absolute;width: 510px;height: 570px;visibility: hidden">
            <img src='pic/00000001.jpg' width='520' height='260' />
            <br>
            <img src='pic/00000002.jpg' width='520' height='260' />
        </div>
        <div id="img" style="left: 10px;top: 10px;position: absolute;width: 400px;height: 420px;visibility: visible">
            <object id="idOcx" name="idOcx" on classid="clsid:4E2CEA6C-A572-40EA-80FE-EC78F1CFA756" width=421
 height=440  align=middle hspace=0  vspace=10  viewastext>
            </object>
        </div>
        <center>
            <table width="100%" border="1" cellspacing="0" cellpadding="0" class="tablist1">
                <tr>
                    <td width="64%" height="566">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td>
                                    <span id="img" style="height: 540px"></span>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td width="36%" height="" valign="top">
                        <span style="width: 35%" class="title1"><a name="tag" class="selectli1">客户信息</a></span>
                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tablist1">
                            <tr>
                                <td width="26%">
                                    公司名称: 
                                </td>
                                <td width="74%">
                                    <span id="coName"></span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    联系人: 
                                </td>
                                <td>
                                    <span id="connector"></span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    联系电话: 
                                </td>
                                <td>
                                    <span id="tel"></span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    备注: 
                                </td>
                                <td>
                                    <span id="remark"></span>
                                </td>
                            </tr>
                        </table>
                        <span style="width: 35%" class="title1"><a name="tag" class="selectli1">票据信息</a></span>
                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tablist1">
                            <tr>
                                <td width="26%" height="34">
                                    账号: 
                                </td>
                                <td width="74%">
                                    <span id="accno"></span>
                                </td>
                            </tr>
                            <tr>
                                <td height="34">
                                    凭证类型: 
                                </td>
                                <td>
                                    <span id="vchtype"></span>
                                </td>
                            </tr>
                            <tr>
                                <td height="34">
                                    批次号: 
                                </td>
                                <td>
                                    <span id="batno"></span>
                                </td>
                            </tr>
                            <tr>
                                <td height="34">
                                    凭证号: 
                                </td>
                                <td>
                                    <span id="vchno"></span>
                                </td>
                            </tr>
                            <tr>
                                <td height="34">
                                    凭证金额: 
                                </td>
                                <td>
                                    <input type="text" id="amount" readonly=true onkeydown="amountEnter(event)"/>
                                </td>
                            </tr>
                            <tr>
                                <td height="34">
                                    凭证日期: 
                                </td>
                                <td>
                                    <input type="text" id="vchdate" readonly=true onkeydown="vchdateEnter(event)"/><!--input type="button" id="resub" value="提交" class="btn1" onClick="resub(1)"/-->
                                </td>
                            </tr>
                            <tr>
                                <td height="34">
                                    提入机构: 
                                </td>
                                <td>
                                    <span id="brbank"></span>
                                </td>
                            </tr>
                            <tr>
                                <td height="34">
                                    查看图像: 
                                </td>
                                <td>
                                    <input type="button" name="see" value="查看" class="btn1" onClick="showImage()"/>
                                </td>
                            </tr>
                        </table><input id="identifyMessegeBox" name="identifyMessegeBox" style="color:#FF0000;border:0px" value="" readonly="true" size="32"/>
                        </tr>
                    </table>
                    <table width="40%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td align="center" valign="bottom">
                                <label>
                                    <input type="button" name="Submit" value="保 存" class="btn1" onClick="saveIdResult();subForm('2')"/>
                                </label>
                                <label>
                                    <input type="button" name="Submit2" value="手工处理" class="btn1" onClick="subForm('4')"/>
                                </label>
                                <label>
                                    <input type="button" name="Submit2" value="下一条" class="btn1" />
                                </label><input type="button" name="Submit3" value="关闭" onClick="self.close()" class="btn1" />
                            </td>
                        </tr>
                    </table>
                    </center>
                </body>
                </html>
